package clientServer;

import java.rmi.RemoteException;

import clientServer.G6PaymentWSImpStub.QueryAccount;
import clientServer.G6PaymentWSImpStub.QueryAccountResponse;
import clientServer.G6PaymentWSImpStub.TransferResponse;


public class WebserviceClientServer {
	/**
	 * @param args
	 * @throws RemoteException 
	 * @throws PaymentWSImplTransactionExceptionException 
	 */
	public static void main(String[] args) throws RemoteException, PaymentWSImpTransactionExceptionException {

		G6PaymentWSImpStub stub = new G6PaymentWSImpStub();
		String accountID1 ="accone";
		String accountID2 ="acctwo";	
		QueryAccounts(stub, accountID1, accountID2);
		//CreateAccounts(stub);
		//Transfer(stub, accountID1, accountID2);
		
	}
	
	public static void Transfer(G6PaymentWSImpStub stub, String accountID1, String accountID2) throws RemoteException{
		QueryAccounts(stub, accountID1, accountID2);
				
		// Call the Second Method of the WebService Payment
		clientServer.G6PaymentWSImpStub.Transfer transfer = new clientServer.G6PaymentWSImpStub.Transfer();
		transfer.setAccountID1(accountID1);
		transfer.setAccountID2(accountID2);
		transfer.setAmount(50);
		TransferResponse transferResponse;
		try {
			transferResponse = stub.transfer(transfer);
			System.out.println("Transfer: " + transferResponse.get_return());
			QueryAccounts(stub, accountID1, accountID2);			
		} catch (PaymentWSImpTransactionExceptionException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

	public static void QueryAccounts(G6PaymentWSImpStub stub, String accountID1, String accountID2) throws RemoteException{
			
		QueryAccount queryAccount = new QueryAccount();
		
		queryAccount.setAccountID(accountID1);
		QueryAccountResponse responseQueryAccount = stub.queryAccount(queryAccount);
		System.out.println("Query Account: " + responseQueryAccount.get_return());
				
		queryAccount.setAccountID(accountID2);
		responseQueryAccount = stub.queryAccount(queryAccount);
		System.out.println("Query Account: " + responseQueryAccount.get_return());
	}
}
